<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page
	import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>禧乐仓连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>
<style>
.datagrid-table {
            table-layout: fixed;
        }
        .datagrid-cell {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .custom-tooltip {
            background: #fff;
            border: 1px solid #ddd;
            padding: 8px;
            border-radius: 4px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            max-width: 400px;
            word-wrap: break-word;
            z-index: 9999;
        }

</style>
<script>

var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	$('#name').textbox('textbox').keydown (function(e){
	    if (event.keyCode == 13){    

	    	findCust();
	 		event.returnValue=false;
	    }
	});
	
	var params = $.serializeObject($('#searchForm'));

	dataGrid = $('#dataGrid').datagrid({
	
		url : 'headQCustMgmtJSONAction!listCustTagData',
		queryParams: params,
		fit : true,
		border : false,
		pagination : true,
		pageSize : 20,
		pageList : [ 20, 30],		
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:false,
		nowrap : false,
		singleSelect:false,
		showFooter:true,
		rownumbers : true,
		sortName : '',
		sortOrder : 'asc',
		rowStyler: function(index,row){
			var style = "";
			if (row.status == 1)
				style += 'color:red;';

			return style;
		},
		columns : [ [
 		    {
				field : 'id',
				title : '账号',
				checkbox:false,
				
				width : 45
			},{	
				field : 'name',
				title : '客户名字',
				width : 180,
				sortable:true,
				order:'desc'
			},{	
				field : 'tags',
				title : '标签',
				width : 150			
			},{			    
				field : 'area',
				title : '地区',
				width : 80,
				sortable:true,
				align: 'center',
				order:'desc',
				formatter: function(value) {
					  return '<div class="datagrid-cell" title="' + value + '">' + value + '</div>';
            }
				
		    }, {
				field : 'phone',
				title : '电话',
				width : 110,
				align: 'center',
				formatter: function(value) {
					  return '<div class="datagrid-cell" title="' + value + '">' + value + '</div>';
              }
		    }, {		    	
				field : 'address',
				title : '地址',
				width : 150,
				formatter: function(value) {
					  return '<div class="datagrid-cell" title="' + value + '">' + value + '</div>';
                }
		    /*}, {	
				field : 'initialAcctBalance',
				title : '期初账目',
				width : 90,
				sortable:true,
				align: 'center',
				order:'desc',
				formatter: function (value, row, index){
					return row.initialAcctBalance.toFixed(2);
				}*/
			},{	
				field : 'currentAcctBalance',
				title : '当前账目',
				width : 90,
				sortable:true,
				align: 'center',
				order:'desc',
				formatter: function (value, row, index){
					return row.currentAcctBalance.toFixed(2);
				}
			},{	
				field : 'currentFinance',
				title : '核对账目',
				width : 90,
				sortable:true,
				align: 'center',
				order:'desc',
				formatter: function (value, row, index){
					return row.currentFinance.toFixed(2);
				}
			},{	
				field : 'currentPrepayAmount',
				title : '当前预存金',
				align: 'center',
				width : 90,
				formatter: function (value, row, index){
					return row.currentPrepayAmount.toFixed(2);
				}
			},{	
				/*				field : 'prepayInitialAmount',
				title : '预存金期初',
				align: 'center',
				width : 90,
				formatter: function (value, row, index){
					return row.prepayInitialAmount.toFixed(2);
				}
			},{	*/
				field : 'prepayComment',
				title : '预存金备注',
				width : 90,
				formatter: function(value) {
					  return '<div class="datagrid-cell" title="' + value + '">' + value + '</div>';
            }
			}, {
				field : 'comment',
				title : '备注信息',
				width : 90,
				formatter: function(value) {
					  return '<div class="datagrid-cell" title="' + value + '">' + value + '</div>';
              }
			}, {
				field : 'status',
				title : '状态',
				width : 80,
				sortable:true,
				align: 'center',
				order:'desc',
				formatter: function (value, row, index){
					if (row.status == 0 )
						return "正常";
					else if (row.status == 1 )
						return "冻结";
				}
			}, {				
				field : 'action',
				title : '编辑',
				width : 70,
				align: 'center',
			formatter : function(value, row, index) {
				var str = '';

					str += $.formatString('<a href="#" onclick="updateCust(\'{0}\');"><img border="0" src="{1}" title="更改客户信息"/></a>', row.id, '<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/update.png');
								
				return str;
			}
		}]],
		toolbar : '#toolbar',
		onLoadSuccess: function() {
	        $('.datagrid-cell').tooltip({
	            position: 'bottom',
	            onShow: function() {
	                $(this).tooltip('tip').css('max-width', '500px'); // 自定义宽度
	            }
	        });
	    }
	});

});




function BSkeyDown(e){

	var ieKey = event.keyCode;
	        
} 

document.onkeydown = BSkeyDown; 


function AddCust(){
	var params = "";

	$.modalDialog.opener_dataGrid = dataGrid;
	
	$.modalDialog({
		title : "新增客户信息",
		width : 480,
		height : 420,
		modal : false,
		draggable:false,
		href : 'headQCustMgmtJSPAction!preEditCust',
		
	});
}
function updateCust(id){
	var params = "formBean.cust.id=" + id;
	$.modalDialog({
		title : "更新客户信息",
		width : 480,
		height : 420,
		modal : false,
		draggable:false,
		href : 'headQCustMgmtJSPAction!preEditCust?' + params,
		
	});
}
function EditCust(){
   var rows = dataGrid.datagrid('getSelections');
	if (rows.length == 0){
		parent.$.messager.alert('错误', '请选中一个客户信息再继续操作', 'error');
		return;
	}
	var	id = rows[0].id;
	updateCust(id);
}
function downloadCust(){
	document.searchForm.action="headQCustMgmtJSPAction!downloadCustExcelReport";
	document.searchForm.submit();
}
function searchCust(){
	dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
}
function cleanSearch(){
	$('#searchForm input').val('');
	dataGrid.datagrid('load', {});
}


/**
 * 批量添加客户标签
 */
function insertCustTags(){
        		var rows = dataGrid.datagrid('getSelections');
        		var param = "";
        		var tagGroups = $('#tags').val();	

        		if(rows.length>0){
        			 $.messager.confirm('批量修改标签', '确认修改客户标签信息吗?', function(r){
        		         if (r){
        		        	 for(let index=0;index < rows.length; index++){
        		        			param = param+"formBean.ids=" + rows[index].id+"&"			
        		        		}				
        		        		var params = param+ "formBean.tagGroups=" + tagGroups;			
        		        		$.post("headQCustMgmtJSONAction!saveBatchEntityTags",params, callBack,"json");
        		         	}
        		        });     			        		
         } else {
 			$.messager.alert('提示','客户信息为空,请选择要添加的客户','warning');
 		}
}

/**
 * 回调
 */
function callBack(data){
	$.messager.alert('提示',data.message,'warning');
	searchCust();
}

function findCust(){
	dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
}


</script>

</head>
<body>
<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',border:false" style="height: 65px;">
	<s:form id="searchForm" name="searchForm"
		theme="simple" method="POST">
		<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
									<tr>
										<td width="6%" align="center"><strong>客户姓名:</strong></td>
										<td width="5%" ><input type="text"  style="width:150px" class="easyui-textbox" value=""  data-options="prompt:'请输入客户名称'" name="formBean.custName" id="name" placeholder="可以模糊查询客户名字" /></td>
										<td width="6%" align="center"><strong>客户状态: </strong></td>
										<td width="5%" align="center">
												<s:select cssClass="easyui-combobox" style="width:150px" name="formBean.custStatus" data-options="prompt:'请选择客户状态!'"   id="custStatus" listKey="key" listValue="value" headerKey="" headerValue="" list="#{'0':'正常','1':'冻结'}" ></s:select>														
										</td>										
										<td width="6%" align="center"><strong>客户标签：</strong></td>
										<td >
												<input class="easyui-tagbox" name="formBean.tagGroups" id="tags"  style="width:38%" data-options="
											                url: 'headQCustMgmtJSONAction!listCusTags',
											                method: 'get',
											                groupField:'groupName',
											                value: '',
											                valueField: 'id',
											                textField: 'tagName',
											                limitToList: true,
											                hasDownArrow: true,
											                prompt: '选择客户标签',
											                tagStyler: function(value){
										                    if (value >0 && value <=3){
										                        return 'background:#ffd7d7;color:#c65353';
										                    } else if (value >= 4 && value <17){
										                        return 'background:#76EEC6;color:#c65353';
										                    }else if (value >= 17 && value <19){
										                        return 'background:#7EC0EE;color:#c65353';
										                    }else if (value >= 19 ){
										                        return 'background:#EEB422;color:#c65353';
										                    }
										                }
											                ">
											             <s:if
														test="(#session.LOGIN_USER.containFunction('headQCustMgmtJSONAction!saveBatchEntityTags')) ">
														<a onclick="insertCustTags();" href="#" style="width: 120px"
															class="easyui-linkbutton"
															data-options="iconCls:'icon-edit',plain:true">批量修改标签</a>
													</s:if> 											                
														</td>				
									</tr>
																
								</table>
							</td>
						</tr>
					</table>
		</s:form>
	</div>	
	<div data-options="region:'center',border:false">
		<table id="dataGrid">
		</table>
			<div id="toolbar" style="display: none;">
				<a onclick="findCust();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-search',plain:true">搜索客户</a> <a
					onclick="AddCust();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-add'">添加客户</a> <a
					onclick="EditCust();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-edit'">修改客户</a><a
					onclick="downloadCust();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-print'">导出客户</a> 

			</div>
		</div>
	
</div>
	
</body>
</html>